package com.ymatou.iapi.livequery.testcase;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.livequery.service.SellerActivityCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.LiveCallService;
import com.ymttest.database.mongo.LiveModelWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.MapUtil;

public class Ts_SellerActivity {
	private static String sellerName = EnvSetup.getData("productsellername");
	private static int sellerId = Integer.parseInt(EnvSetup.getData("productsellerid"));
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("买手主页直播列表");
	}

	@Before
	public void caseUp() {
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(new SellerActivityCall().getOpurl());
	}
	
	
	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetSellerActivity_001() {
		Logger.start(true, "买手主页直播列表-获取进行中直播");
		try{
			int liveId = LiveCallService.createLiveInProgress(sellerName, sellerId).getJSONObject("Data").getInt("ActivityId");
			
			JSONObject retBean = new SellerActivityCall().callAndGetReturnData(MapUtil.hashMap("SellerId", sellerId, "IsSingle", true));
			
			Logger.verifyEquals(200,retBean.getInt("Code"),  "响应报文-返回码");
			
			Logger.verifyIsNull(retBean.getJSONObject("Data").getString("HistoryActivities"), "响应报文-HistoryActivities");
			Logger.verifyEquals(liveId,retBean.getJSONObject("Data").getJSONObject("InProgressActivity").getInt("ActivityId"), "响应报文-ActivityId");
			
		}catch (Exception e) {
			// TODO: handle exception
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetSellerActivity_002() {
		Logger.start(true, "买手主页直播列表-获取所有直播");
		try{
			LiveCallService.createLiveInProgress(sellerName, sellerId).getJSONObject("Data").getInt("ActivityId");
			int liveId = LiveCallService.createLiveInProgress(sellerName, sellerId).getJSONObject("Data").getInt("ActivityId");
			
			JSONObject retBean = new SellerActivityCall().callAndGetReturnData(MapUtil.hashMap("SellerId", sellerId, "IsSingle", false));
			
			Logger.verifyEquals(200,retBean.getInt("Code"), "响应报文-返回码");
			
			Logger.verifyEquals(true,retBean.getJSONObject("Data").getJSONArray("HistoryActivities").length()>0,"响应报文-HistoryActivities");
			Logger.verifyEquals(liveId,retBean.getJSONObject("Data").getJSONObject("InProgressActivity").getInt("ActivityId"), "响应报文-ActivityId");
			

			
		}catch (Exception e) {
			// TODO: handle exception
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetSellerActivity_003() {
		Logger.start(true, "买手主页直播列表-获取将要进行直播");
		try{
			
			int liveId = LiveCallService.createLiveBeginInFuture(sellerName, sellerId).getJSONObject("Data").getInt("ActivityId");
			
			JSONObject retBean = new SellerActivityCall().callAndGetReturnData(MapUtil.hashMap("SellerId", sellerId, "IsSingle", false));
			new LiveModelWapper().getActivityId(liveId);
			Logger.verifyEquals(200,retBean.getInt("Code"), "响应报文-返回码");
			Logger.verifyEquals("null",retBean.getJSONObject("Data").get("UpcomingActivities").toString(),"将要进行直播不需要展示");
		}catch (Exception e) {
			// TODO: handle exception
			Logger.fail(e);
		}
	}
	
	
	
	
	
	
}
	
